package com.bilibili.controller;

import com.bilibili.dto.CartoonDto;
import com.bilibili.entity.PicCartoon;
import com.bilibili.entity.PicCategory;
import com.bilibili.entity.Video;
import com.bilibili.service.PicCartoonService;
import com.bilibili.vo.UserLoginVo;
import org.checkerframework.checker.units.qual.C;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 漫画信息相关的Controller
 * @Author Sandy
 */
@RestController
@RequestMapping("pic_cartoon")
public class PicCartoonController {

    @Autowired
    private PicCartoonService picCartoonService;

    /**
     * @return 拿到所有的漫画
     */
//    @RequestMapping(value = "all", method = RequestMethod.GET)
    @RequestMapping(method = RequestMethod.GET)
    public List<PicCartoon> getAllCartoons() {
        return picCartoonService.getAllCartoon();
    }


    /**
     *
     * @param cartoonId 漫画id
     * @return 通过漫画id拿到一个漫画
     */
//    @RequestMapping(value = "getCartoonById", method = RequestMethod.GET, params = {"cartoonId"})
    @RequestMapping(value = "{cartoonId}", method = RequestMethod.GET, params = {"select_type=cartoonId"})
    public PicCartoon getCartoonById(@PathVariable("cartoonId") Integer cartoonId) {
        return picCartoonService.getCartoonById(cartoonId);
    }

    /**
     * @param name 题材的名字
     * @return 通过该名字拿到的id
     */
//    @RequestMapping(value = "getCartoonByCategory", method = RequestMethod.GET)
    @RequestMapping(value = "{name}", method = RequestMethod.GET, params = {"select_type=name"} )
    public List<PicCartoon> getRandomCartoonByCategory(@PathVariable("name") String name) {
        return picCartoonService.getRandomAdventureCartoons(name);
    }
    /**
     *
     * @param categoryId 题材id
     * @return 通过题材id拿到的漫画
     */
//    @RequestMapping(value = "getByCategoryId", method = RequestMethod.GET, params = {"categoryId"})
    @RequestMapping(value = "{categoryId}", method = RequestMethod.GET , params = {"select_type=categoryId"})
    public List<PicCartoon> getCartoonsCategoryId(@PathVariable("categoryId") Integer categoryId ) {
        return picCartoonService.getCartoonByCategoryId(categoryId);
    }
    /**
     * @param categoryId 题材id
     * @param regionId   国家id
     * @return 题材id和国家id两个id筛选得到的漫画
     */
//    @RequestMapping(value = "classification", method = RequestMethod.GET, params = {"categoryId", "regionId"})
    @RequestMapping(method = RequestMethod.GET, params = {"categoryId", "regionId"})
    public List<PicCartoon> getCartoonsCategory(@RequestParam(name = "categoryId") Integer categoryId, @RequestParam(name = "regionId") Integer regionId) {
        return picCartoonService.getCartoonByIds(categoryId, regionId);
    }

    /**
     * @param keyword 搜索关键字
     * @return 通过模糊查询得到的漫画
     */
    @RequestMapping(value = "search", method = RequestMethod.GET)
    public List<PicCartoon> getAllCartoons(@RequestParam(name = "keyword") String keyword) {
        return picCartoonService.getCartoonBySearch(keyword);
    }

    /**
     * @return 拿到五给随机且不重复的漫画
     */
    @RequestMapping(value = "random", method = RequestMethod.GET)
    public List<PicCartoon> getRandomCartoons() {
        return picCartoonService.getRandomCartoons();
    }



    /**
     * @param picCartoon 用于插入的漫画实体类(其中属性传入时并没有进行检查,会在该1方法进行校验)
     * @return 插入成功后该漫画的id
     */
    @RequestMapping(method = RequestMethod.POST)
    public PicCartoon addCartoon(@RequestBody PicCartoon picCartoon) {
        return picCartoonService.addCartoon(picCartoon);
    }

    /**
     * 查询随机漫画列表
     *
     * @return 随机商品列表
     * @Author YM
     */
    @RequestMapping(method = RequestMethod.GET, params = {"fetch_type=random"})
    public List<CartoonDto> getIndexRandomCartoons() {
        return picCartoonService.getIndexRandomCartoons();
    }

    /**
     * 查询最热漫画列表
     *
     * @return 最热漫画列表
     * @Author YM
     */
    @RequestMapping(method = RequestMethod.GET, params = {"fetch_type=hotest"})
    public List<PicCartoon> getHotestVideos() {
        return picCartoonService.getHotestCartoons();
    }



}
